package com.z.system.controller;

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.z.system.service.PermissionService;
import com.z.system.utils.R;
import com.z.system.vo.Menu;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 菜单控制器
 */
@RestController
@RequestMapping("/api/system/menus")
@Tag(name = "菜单管理", description = "菜单相关接口")
public class MenuController {

    private final PermissionService permissionService;

    public MenuController(PermissionService permissionService) {
        this.permissionService = permissionService;
    }

    /**
     * 获取当前登录用户的菜单权限
     * 所有认证用户都可以访问
     */
    @GetMapping("/simple")
    @PreAuthorize("isAuthenticated()")
    @Operation(summary = "获取用户菜单列表", description = "获取当前登录用户的菜单权限列表", responses = @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "菜单列表", content = @Content(schema = @Schema(implementation = List.class))))
    public ResponseEntity<R<List<Menu>>> getCurrentUserMenus() {
        List<Menu> menus = permissionService.getCurrentUserMenus();
        return ResponseEntity.ok(R.success(menus));
    }

}